/**
 * 信用系统常量配置
 */

// 信用分等级配置
export const CREDIT_LEVELS = {
  EXCELLENT: {
    level: 'excellent',
    name: '优秀',
    minScore: 800,
    maxScore: 850,
    color: '#67C23A',
    bgColor: '#f0f9ff',
    icon: 'el-icon-medal',
    benefits: ['最高优惠', '免押金服务', '优先客服']
  },
  GOOD: {
    level: 'good',
    name: '良好',
    minScore: 750,
    maxScore: 799,
    color: '#409EFF',
    bgColor: '#ecf5ff',
    icon: 'el-icon-trophy',
    benefits: ['高级优惠', '部分免押金', '快速审核']
  },
  MEDIUM: {
    level: 'medium',
    name: '中等',
    minScore: 700,
    maxScore: 749,
    color: '#E6A23C',
    bgColor: '#fdf6ec',
    icon: 'el-icon-star-on',
    benefits: ['基础优惠', '标准服务']
  },
  FAIR: {
    level: 'fair',
    name: '一般',
    minScore: 650,
    maxScore: 699,
    color: '#F56C6C',
    bgColor: '#fef0f0',
    icon: 'el-icon-star-off',
    benefits: ['基础服务']
  },
  POOR: {
    level: 'poor',
    name: '较差',
    minScore: 350,
    maxScore: 649,
    color: '#909399',
    bgColor: '#f4f4f5',
    icon: 'el-icon-warning-outline',
    benefits: ['限制服务']
  }
}

// 信用分范围
export const CREDIT_SCORE_RANGE = {
  MIN: 350,
  MAX: 850,
  DEFAULT: 600
}

// 服务类型常量
export const SERVICE_TYPES = {
  LIFE_SERVICE: {
    type: 'life_service',
    name: '生活服务',
    icon: 'el-icon-house',
    color: '#409EFF',
    requiredScore: 650
  },
  RENTAL: {
    type: 'rental',
    name: '租房服务',
    icon: 'el-icon-key',
    color: '#67C23A',
    requiredScore: 720
  },
  HOTEL: {
    type: 'hotel',
    name: '酒店预订',
    icon: 'el-icon-office-building',
    color: '#E6A23C',
    requiredScore: 700
  },
  GOODS: {
    type: 'goods',
    name: '商品购买',
    icon: 'el-icon-shopping-cart-full',
    color: '#F56C6C',
    requiredScore: 680
  }
}

// 活动类型常量
export const ACTIVITY_TYPES = {
  RECYCLE: {
    type: 'recycle',
    name: '资源回收',
    icon: 'el-icon-refresh',
    color: '#67C23A',
    category: 'prosocial'
  },
  WATER_PROTECTION: {
    type: 'water_protection',
    name: '护水活动',
    icon: 'el-icon-water',
    color: '#409EFF',
    category: 'prosocial'
  },
  CHARITY: {
    type: 'charity',
    name: '公益活动',
    icon: 'el-icon-heart',
    color: '#F56C6C',
    category: 'prosocial'
  },
  VOLUNTEER: {
    type: 'volunteer',
    name: '志愿服务',
    icon: 'el-icon-user',
    color: '#E6A23C',
    category: 'prosocial'
  }
}

// 任务类型常量
export const TASK_TYPES = {
  BASIC: {
    type: 'basic',
    name: '基础任务',
    icon: 'el-icon-edit',
    color: '#909399',
    pointsRange: [5, 15]
  },
  IDENTITY: {
    type: 'identity',
    name: '身份认证',
    icon: 'el-icon-user-solid',
    color: '#409EFF',
    pointsRange: [10, 20]
  },
  ACTIVITY: {
    type: 'activity',
    name: '活动参与',
    icon: 'el-icon-present',
    color: '#67C23A',
    pointsRange: [15, 30]
  },
  REFERRAL: {
    type: 'referral',
    name: '推广邀请',
    icon: 'el-icon-share',
    color: '#E6A23C',
    pointsRange: [20, 40]
  },
  CHARITY: {
    type: 'charity',
    name: '公益行为',
    icon: 'el-icon-heart',
    color: '#F56C6C',
    pointsRange: [25, 50]
  }
}

// 状态常量
export const STATUS = {
  ACTIVE: {
    value: '0',
    label: '正常',
    color: 'success'
  },
  INACTIVE: {
    value: '1',
    label: '停用',
    color: 'danger'
  },
  PENDING: {
    value: '2',
    label: '待审核',
    color: 'warning'
  },
  EXPIRED: {
    value: '3',
    label: '已过期',
    color: 'info'
  }
}

// 订单状态
export const ORDER_STATUS = {
  PENDING: {
    value: 'pending',
    label: '待确认',
    color: 'warning'
  },
  CONFIRMED: {
    value: 'confirmed',
    label: '已确认',
    color: 'primary'
  },
  PROCESSING: {
    value: 'processing',
    label: '处理中',
    color: 'info'
  },
  COMPLETED: {
    value: 'completed',
    label: '已完成',
    color: 'success'
  },
  CANCELLED: {
    value: 'cancelled',
    label: '已取消',
    color: 'danger'
  }
}

// 支付方式
export const PAYMENT_METHODS = {
  ALIPAY: {
    value: 'alipay',
    label: '支付宝',
    icon: 'alipay'
  },
  WECHAT: {
    value: 'wechat',
    label: '微信支付',
    icon: 'wechat'
  },
  BANK_CARD: {
    value: 'bank_card',
    label: '银行卡',
    icon: 'credit-card'
  },
  CREDIT_POINTS: {
    value: 'credit_points',
    label: '信用积分',
    icon: 'star'
  }
}

// 图表颜色配置
export const CHART_COLORS = {
  PRIMARY: '#409EFF',
  SUCCESS: '#67C23A',
  WARNING: '#E6A23C',
  DANGER: '#F56C6C',
  INFO: '#909399',
  LIGHT: '#C0C4CC',
  DARK: '#303133'
}

// 地区代码
export const REGION_CODES = {
  GUANGDONG: '440000',
  BEIJING: '110000',
  SHANGHAI: '310000',
  JIANGSU: '320000',
  ZHEJIANG: '330000',
  SHANDONG: '370000'
}

// 文件类型
export const FILE_TYPES = {
  IMAGE: {
    extensions: ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'],
    maxSize: 5 * 1024 * 1024, // 5MB
    accept: 'image/*'
  },
  DOCUMENT: {
    extensions: ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx'],
    maxSize: 10 * 1024 * 1024, // 10MB
    accept: '.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx'
  },
  VIDEO: {
    extensions: ['mp4', 'avi', 'mov', 'wmv', 'flv', 'mkv'],
    maxSize: 50 * 1024 * 1024, // 50MB
    accept: 'video/*'
  }
}

// API 错误码
export const ERROR_CODES = {
  SUCCESS: 200,
  BAD_REQUEST: 400,
  UNAUTHORIZED: 401,
  FORBIDDEN: 403,
  NOT_FOUND: 404,
  METHOD_NOT_ALLOWED: 405,
  INTERNAL_SERVER_ERROR: 500,
  SERVICE_UNAVAILABLE: 503
}

// 本地存储键名
export const STORAGE_KEYS = {
  TOKEN: 'credit_token',
  USER_INFO: 'credit_user_info',
  SETTINGS: 'credit_settings',
  THEME: 'credit_theme',
  LANG: 'credit_lang'
}

// 分页配置
export const PAGINATION_CONFIG = {
  DEFAULT_PAGE_SIZE: 10,
  PAGE_SIZES: [10, 20, 50, 100],
  SHOW_TOTAL: true,
  SHOW_ELEVATOR: true,
  SHOW_SIZER: true
}

// 日期格式
export const DATE_FORMATS = {
  DATE: 'YYYY-MM-DD',
  TIME: 'HH:mm:ss',
  DATETIME: 'YYYY-MM-DD HH:mm:ss',
  MONTH: 'YYYY-MM',
  YEAR: 'YYYY'
}

// 正则表达式
export const REGEX_PATTERNS = {
  PHONE: /^1[3-9]\d{9}$/,
  EMAIL: /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/,
  ID_CARD: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
  PASSWORD: /^(?=.*[a-zA-Z])(?=.*\d)[^]{6,20}$/,
  URL: /^https?:\/\/(([a-zA-Z0-9_-])+(\.)?)*(:\d+)?(\/((\.)?(\?)?=?&?[a-zA-Z0-9_-](\?)?)*)*$/i,
  IP: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
}

// 消息类型
export const MESSAGE_TYPES = {
  CREDIT_CHANGE: {
    type: 'credit_change',
    name: '信用分变动',
    icon: 'el-icon-star-on'
  },
  TASK_COMPLETION: {
    type: 'task_completion',
    name: '任务完成',
    icon: 'el-icon-check'
  },
  ACTIVITY_INVITATION: {
    type: 'activity_invitation',
    name: '活动邀请',
    icon: 'el-icon-present'
  },
  SERVICE_CONFIRMATION: {
    type: 'service_confirmation',
    name: '服务确认',
    icon: 'el-icon-goods'
  },
  SYSTEM_NOTICE: {
    type: 'system_notice',
    name: '系统通知',
    icon: 'el-icon-bell'
  }
}

// 主题配置
export const THEME_CONFIG = {
  LIGHT: {
    name: 'light',
    label: '浅色主题',
    primary: '#409EFF',
    background: '#ffffff',
    text: '#303133'
  },
  DARK: {
    name: 'dark',
    label: '深色主题',
    primary: '#409EFF',
    background: '#1f1f1f',
    text: '#ffffff'
  }
}

// 动画配置
export const ANIMATION_CONFIG = {
  DURATION: {
    FAST: 200,
    NORMAL: 300,
    SLOW: 500
  },
  EASING: {
    EASE: 'ease',
    EASE_IN: 'ease-in',
    EASE_OUT: 'ease-out',
    EASE_IN_OUT: 'ease-in-out'
  }
}

// 获取常量值的辅助函数
export function getConstantByValue(constants, value) {
  return Object.values(constants).find(item => item.value === value)
}

export function getConstantOptions(constants) {
  return Object.values(constants).map(item => ({
    label: item.label || item.name,
    value: item.value || item.type,
    ...item
  }))
}

export function getConstantMap(constants) {
  const map = {}
  Object.values(constants).forEach(item => {
    map[item.value || item.type] = item
  })
  return map
} 